<?php

function pr($data)
{
    echo '<pre>';
    print_r($data);
    echo '</pre>';
    die;
}

function slide($menuId)
{
    return \App\Models\Slide::where('menu_id', $menuId)
        ->where('isShow', 1)->get();
}

function news($menuId, $take = null)
{
    $New = new  \App\Models\News();
    if ($take) {
        $New = $New->take($take);
    }
    return $New->where('menu_id', $menuId)
        ->where('isShow', 1)
        ->orderBy('sort', 'desc')->get();
}

function menuNew($menuIds, $take = 2)
{
    $New = new  \App\Models\News();
    $New = $New->take($take);
    return $New->whereIn('menu_id', $menuIds)
        ->where('isShow', 1)
        ->orderBy('sort', 'desc')->get();
}

function navMenu()
{
    return \App\Models\Menu::where('isShow', 1)
        ->where('type', 4)
        ->orderBy('sort')
        ->get();
}

function menuChild($menuId, $with = null)
{
    $Menu = new App\Models\Menu();
    if ($with) {
        $Menu->with($with);
    }
    $menu = $Menu->where('isShow', 1)
        ->where('parentId', $menuId)
        ->get();
    return $menu;
}
function linkMenuList($id){
    return url('home/news/lists').'/'.$id;
}
function linkNew($id){
    return url('home/news/content').'/'.$id;
}
function newsPage($news){
   $next= \App\Models\News::where('id','>',$news->id)
       ->orderBy('id')->first();
   $before=\App\Models\News::where('id','<',$news->id)
       ->orderBy('id','desc')->first();
   return compact('next','before');
}



